package zust.se.ssm.service.impl;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import zust.se.ssm.dto.UserDto;
import zust.se.ssm.form.UserLoginForm;
import zust.se.ssm.mapper.UserMapper;
import zust.se.ssm.model.User;
import zust.se.ssm.service.UserServiceI;

import javax.annotation.Resource;
import java.util.List;

/**
 * 
 * @author czg
 * @since 2023/6/6 17:16
 */
@Service
@Transactional
public class UserServiceImpl implements UserServiceI {
    @Resource
    UserMapper userMapper;
    @Override
    public UserDto login(UserLoginForm loginForm) {
        List<User> userList=userMapper.getUserByLoginName(loginForm.getLoginName());
        if(userList==null||userList.size()!=1)
            return null;
        if(!userList.get(0).getPassword().equals(loginForm.getPassword()))
            return null;
        UserDto dto=new UserDto();
        BeanUtils.copyProperties(userList.get(0),dto);
        return dto;
    }
}
